package com.frejoys.listener;

import com.frejoys.listener.event.OrderQrCodeEvent;
import com.frejoys.listener.event.OrderVerifyEvent;
import com.frejoys.listener.event.StoreQrCodeEvent;
import com.frejoys.listener.event.UserQrCodeEvent;
import com.frejoys.service.EventPublisherService;
import lombok.RequiredArgsConstructor;
import org.springframework.context.event.EventListener;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

// 蜂场蜂箱数量统计事件
@Service
@RequiredArgsConstructor
public class EventListenerService {

    private final EventPublisherService eventPublisherService;

    /**
     * 监听用户二维码
     * @param event
     */
    @Async
    @EventListener
    public void wxQrCode(UserQrCodeEvent event) {
        eventPublisherService.dispatchUserQrCodeService(event.getUserId(), event.getSite());
    }

    /**
     * 监听订单二维码
     * @param event
     */
    @Async
    @EventListener
    public void orderQrCode(OrderQrCodeEvent event) {
        eventPublisherService.dispatchOrderQrCodeService(event.getOrderSn());
    }

    /**
     * 监听店铺线上支付二维码
     * @param event
     */
    @Async
    @EventListener
    public void storePayQrCode(StoreQrCodeEvent event) {
        eventPublisherService.dispatchStoreQrCodeService(event.getStoreId(), event.getType());
    }

}
